#! /usr/local/bin/python

import cgi
import urllib
import urllib2

blogurl  = 'http://www.cs.cityu.edu.hk/~cs4380/webservice/blog/getPost.py'
username = '51158405'
passwd   = 'gxlty725'


















# get url variables 
form = cgi.FieldStorage()
author = str(form["author"].value)

# setup the password
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_manager.add_password(None, 'http://www.cs.cityu.edu.hk/', username, passwd)
auth_handler = urllib2.HTTPBasicAuthHandler(password_manager)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)

# setup the parameters for calling the web service
params = urllib.urlencode({
	'author': author, 
	'type': 'json'
})

# call the webservice
data = urllib2.urlopen(blogurl, params).read()

print 'Content-type: text/html\n\n'
print data
